package com.lightsh.body;

import org.jbox2d.collision.shapes.Shape;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.contacts.ContactPoint;
import org.jbox2d.dynamics.contacts.ContactResult;

import com.lightsh.graphics.Sprite;
import com.lightsh.object.BaseObject;
import com.lightsh.utility.Constants;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;

/**
 * 所有jbox2d物体的基类
 * @author Light
 *
 */
public class BaseBody extends BaseObject{	
	protected BodyDef mBodyDef;
	protected Body mBody;
	protected Shape mShape;	
	protected Path mPath;
	
	public BaseBody(){
		super();
		mBodyDef = new BodyDef();
		mBodyDef.userData = this;
	}

	@Override
	public void draw(Canvas canvas, Rect screenRect){
		draw(canvas, screenRect, 1f, 1f);
	}
	
	@Override
	public void draw(Canvas canvas, Rect screenRect, float selfScale){
		draw(canvas, screenRect, selfScale, 1f);
	}
	
	@Override
	public void draw(Canvas canvas, Rect screenRect, float selfScale, float worldScale){
		// do nothing
	}
	
	@Override
	public void update(){
		super.update();
	}
	
	@Override
	public Vec2 getPosition(){
//		return mBody.m_xf.position;
		return mBody.getPosition();
	}
	
	/**
	 * 设置物体运动的阻尼值
	 * @param damping
	 */
	public void setLinearDamping(float damping){
		mBody.setLinearDamping(damping);
	}
	
	public Body getBody(){
		return mBody;
	}
	
	/**
	 * 当跟其他物体发生碰撞时回调该方法，body需要在该方法中保存需要执行的操作，待到{@link #update()}时正式执行
	 * @param point			碰撞的信息
	 */
	public void onContactAdd(ContactPoint point){
		
	}
	
	public void onContactPersist(ContactPoint point){
		
	}
	public void onContactRemove(ContactPoint point){
		
	}
	public void onContactResult(ContactResult result){
		
	}
}
